/**
 * @license
 * Copyright JINSCOP. All Rights Reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 */

// locally used mixin
@mixin hover-border($color) {
  .customised-control-input:checked ~ .customised-control-indicator {
    border-color: $color;
  }
  .customised-control-input:hover:enabled ~ .customised-control-indicator {
    border-color: lighten($color, 10%);
  }
}
// locally used mixin
@mixin checkbox-checkmark($size, $color, $border-size) {
  &::before {
    content: '';
    position: absolute;
    height: calc(#{$size} * 0.6);
    width: calc(#{$size} * 0.4);
    border: solid $color;
    border-width: 0 $border-size $border-size 0;
    transform: rotate(45deg);
  }
}
// locally used mixin
@mixin set-style($bg, $size, $border-size, $border-color) {
  background-color: $bg;
  width: $size;
  height: $size;
  border: $border-size solid $border-color;
}
// locally used mixin
@mixin description-style {
  color: nb-theme(color-fg-heading);
  @include nb-ltr(padding-left, 0.25rem);
  @include nb-rtl(padding-right, 0.25rem);
}

@mixin nb-checkbox-theme() {
  nb-checkbox {
    .customised-control {
      position: relative;
      display: inline-flex;
      margin: 0;
      min-height: inherit;
      padding: 0.375rem 1.5rem;
    }

    .customised-control-indicator {
      @include set-style(
          nb-theme(checkbox-bg),
          nb-theme(checkbox-size),
          nb-theme(checkbox-border-size),
          nb-theme(checkbox-border-color)
      );

      border-radius: 0.25rem;
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      @include nb-ltr(left, 0);
      @include nb-rtl(right, 0);
      flex: none;
      display: flex;
      justify-content: center;

      @include checkbox-checkmark(
          nb-theme(checkbox-size),
          nb-theme(checkbox-checkmark),
          nb-theme(checkbox-border-size)
      );
    }

    .customised-control-input {
      position: absolute;
      opacity: 0;
      z-index: -1;
    }

    .customised-control-input {
      &:checked ~ .customised-control-indicator {
        @include set-style(
            nb-theme(checkbox-checked-bg),
            nb-theme(checkbox-checked-size),
            nb-theme(checkbox-checked-border-size),
            nb-theme(checkbox-checked-border-color)
        );

        display: flex;
        justify-content: center;

        @include checkbox-checkmark(
            nb-theme(checkbox-checked-size),
            nb-theme(checkbox-checked-checkmark),
            nb-theme(checkbox-checked-border-size)
        );
      }

      &:disabled ~ {
        .customised-control-indicator {
          @include set-style(
              nb-theme(checkbox-disabled-bg),
              nb-theme(checkbox-disabled-size),
              nb-theme(checkbox-disabled-border-size),
              nb-theme(checkbox-border-color)
          );
          opacity: 0.5;
          display: flex;
          justify-content: center;

          @include checkbox-checkmark(
              nb-theme(checkbox-disabled-size),
              nb-theme(checkbox-checkmark),
              nb-theme(checkbox-disabled-border-size)
          );
        }

        .customised-control-description {
          opacity: 0.5;
          @include description-style;
        }
      }

      &:disabled:checked ~ {
        .customised-control-indicator {
          @include set-style(
              nb-theme(checkbox-disabled-bg),
              nb-theme(checkbox-disabled-size),
              nb-theme(checkbox-disabled-border-size),
              nb-theme(checkbox-checked-border-color)
          );
          opacity: 0.5;
          display: flex;
          justify-content: center;

          @include checkbox-checkmark(
              nb-theme(checkbox-disabled-size),
              nb-theme(checkbox-disabled-checkmark),
              nb-theme(checkbox-disabled-border-size)
          );
        }

        .customised-control-description {
          opacity: 0.5;
          @include description-style;
        }
      }
    }

    @include hover-border(nb-theme(checkbox-checked-border-color));
    &.success {
      @include hover-border(nb-theme(color-success));
    }
    &.warning {
      @include hover-border(nb-theme(color-warning));
    }
    &.danger {
      @include hover-border(nb-theme(color-danger));
    }

    .customised-control-description {
      @include description-style;
    }
  }
}

